memshr: Build fixes
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 28 Dec 2009 09:14:16 +0000 (09:14 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 28 Dec 2009 09:14:16 +0000 (09:14 +0000)
 * Build memshr/xenpaging on x86/Linux only
 * Remove dependency on GCC 4.1+ __sync_*() intrinsics.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
Signed-off-by: KUWAMURA Shin'ya <kuwa@jp.fujitsu.com>
tools/Makefile
tools/Rules.mk
tools/memshr/bidir-hash.c

index 478fc3d8f4d46f22c1190dd771fbcbf3c2fdb628..d5cffa292382deb1dadc574cda70959961912575 100644 (file)
@@ -21,7 +21,6 @@ SUBDIRS-$(VTPM_TOOLS) += vtpm_manager
 SUBDIRS-$(VTPM_TOOLS) += vtpm
 SUBDIRS-y += xenstat
 SUBDIRS-$(CONFIG_Linux) += libaio
-SUBDIRS-$(CONFIG_Linux) += memshr 
 SUBDIRS-$(CONFIG_Linux) += blktap
 SUBDIRS-$(CONFIG_Linux) += blktap2
 SUBDIRS-$(CONFIG_NetBSD) += libaio
@@ -35,7 +34,9 @@ SUBDIRS-$(CONFIG_IOEMU) += ioemu-dir
 SUBDIRS-y += xenpmd
 SUBDIRS-y += libxl
 SUBDIRS-y += remus
-SUBDIRS-y += xenpaging
+
+SUBDIRS-$(CONFIG_X86)$(CONFIG_Linux) += memshr 
+SUBDIRS-$(CONFIG_X86)$(CONFIG_Linux) += xenpaging
 
 # These don't cross-compile
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
index 53d8aa86ce19479d0ef572b58f1eb861ef7ae9d9..83899d3cbd734c71ee50ecf10a371f2c7b6739d0 100644 (file)
@@ -64,7 +64,7 @@ INSTALL_PYTHON_PROG = \
        $(CC) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
 
 subdirs-all subdirs-clean subdirs-install: .phony
-       @set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y); do \
+       @set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y) $(SUBDIRS-yy); do \
                $(MAKE) subdir-$(patsubst subdirs-%,%,$@)-$$subdir; \
        done
 
index e421c221dfce287d8fc54cca6cac08e1063c04af..e3e0e15831dd52b22fab37dbd179763c4022aa90 100644 (file)
@@ -75,7 +75,7 @@ struct __hash
                                            * *_tab, tab_size, size_idx, *_load
                                            * (all writes with wrlock)
                                            */
-    volatile uint32_t nr_ent;             /* # entries held in hashtables */
+    uint32_t nr_ent;                      /* # entries held in hashtables */
     struct bucket *key_tab;               /* forward mapping hashtable    */
     struct bucket *value_tab;             /* backward mapping hashtable   */
     struct bucket_lock *key_lock_tab;     /* key table bucket locks       */
@@ -100,6 +100,21 @@ int            __hash_iterator(struct __hash *h,
                         void *d);
 static void      hash_resize(struct __hash *h);
 
+static inline void atomic_add(uint32_t *v, uint32_t i)
+{
+    asm volatile(
+        "lock ; addl %1,%0"
+        :"=m" (*(volatile uint32_t *)v)
+        :"ir" (i), "m" (*(volatile uint32_t *)v) );
+}
+
+static inline void atomic_sub(uint32_t *v, uint32_t i)
+{
+    asm volatile (
+        "lock ; subl %1,%0"
+        : "=m" (*(volatile uint32_t *)v)
+        : "ir" (i), "m" (*(volatile uint32_t *)v) );
+}
 
 #ifdef BIDIR_USE_STDMALLOC
 
@@ -759,7 +774,6 @@ int __insert(struct __hash *h, __k_t k, __v_t v)
     struct bucket *bk, *bv;
     struct bucket_lock *bltk, *bltv;
 
-
     /* Allocate new entry before any locks (in case it fails) */
     entry = (struct hash_entry*)
                     alloc_entry(h, sizeof(struct hash_entry));
@@ -797,7 +811,7 @@ int __insert(struct __hash *h, __k_t k, __v_t v)
     TWO_BUCKETS_LOCK_WRUNLOCK(h, bltk, k_idx, bltv, v_idx);
 
     /* Book keeping */
-    __sync_add_and_fetch(&h->nr_ent, 1);
+    atomic_add(&h->nr_ent, 1);
 
     HASH_LOCK_RDUNLOCK(h);
 
@@ -931,7 +945,8 @@ found_again:
             *pek = e->__prim_next;
             *pev = e->__sec_next;
 
-            nr_ent = __sync_sub_and_fetch(&h->nr_ent, 1);
+            atomic_sub(&h->nr_ent, 1);
+            nr_ent = h->nr_ent;
             /* read min_load still under the hash lock! */
             min_load = h->min_load;
 
@@ -1079,7 +1094,8 @@ found_again:
             *pek = e->__prim_next;
             *pev = e->__sec_next;
 
-            nr_ent = __sync_sub_and_fetch(&h->nr_ent, 1);
+            atomic_sub(&h->nr_ent, 1);
+            nr_ent = h->nr_ent;
             /* read min_load still under the hash lock! */
             min_load = h->min_load;